package study.source.common.util;

import java.io.FileOutputStream;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.multipart.MultipartFile;

public class FileUtil {
	
	private FileOutputStream fos;
	private String path;
	
	public String fileUpload(HttpServletRequest request, MultipartFile excelFile){
		
		path = request.getSession().getServletContext().getRealPath("/") + "ExcelUpfile/";
		
		MultipartFile multipartFile = excelFile;
		
		String orgFileName = multipartFile.getOriginalFilename();
		System.out.println(path);
		System.out.println(orgFileName);
		try{
			byte[] fileData = multipartFile.getBytes();
			
			fos = new FileOutputStream(path + orgFileName);
			fos.write(fileData);
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(fos != null){
				try{
					fos.close();
				}catch(Exception e){}
			}
		}
		
		return path+orgFileName;
	}
	
}
